// 修改后的loadComponents.js
async function loadComponent(componentName) {
  try {
    // 使用完整的相对路径
    const response = await fetch(`./components/${componentName}.html`);
    
    if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
    
    const html = await response.text();
    const placeholders = document.querySelectorAll(
      `[data-component="${componentName}"]`
    );
    
    placeholders.forEach(el => {
      el.innerHTML = html;
      console.log(`${componentName} loaded`);
    });
  } catch (error) {
    console.error(`Error loading ${componentName}:`, error);
    
    // 提供备用内容
    const placeholders = document.querySelectorAll(
      `[data-component="${componentName}"]`
    );
    placeholders.forEach(el => {
      el.innerHTML = `<div class="error">模块加载失败: ${componentName}</div>`;
    });
  }
}

// 确保DOM完全加载
document.addEventListener('DOMContentLoaded', () => {
  // 加载所有需要的组件
  ['aiagent','assistant', 'conformity', 'strength', 'customers','footer'].forEach(comp => {
    loadComponent(comp);
  });
});